﻿//隐藏同级其他元素
function only_show(obj) {
    var objparent = obj.parentNode; //父元素
    var objsiblings = objparent.childNodes;//父元素下的所有元素
    for (var i = 0; i < objsiblings.length; i++) {//隐藏所有同级元素
        var objsibling = objsiblings.item(i);
        if (objsibling.tagName && objsibling.tagName.toLowerCase() == obj.tagName.toLowerCase()) {
            objsibling.style.display = "none";
        }
    }
    obj.style.display = "block";
}

//设置元素样式为style1，其他同级元素样式变为style2
function only_class(obj,style1,style2) {
    var objparent = obj.parentNode; //父元素
    var objsiblings = objparent.childNodes; //父元素下的所有元素
    for (var i = 0; i < objsiblings.length; i++) {
        var objsibling = objsiblings.item(i);
        if (objsibling.tagName && objsibling.tagName.toLowerCase() == obj.tagName.toLowerCase()) {
            objsibling.className = style2;
        }
    }
    obj.className = style1;
}


function selthemenu(obj,the_url) {
    var menuary = obj.childNodes;
    for (var i = 0; i < menuary.length; i++) {

        if (menuary.item(i).tagName && menuary.item(i).tagName.toLowerCase() == "div") {//判断菜单
            var linkmenu = menuary.item(i).getElementsByTagName("a"); //获取超链接
            linkmenu.item(0).href = linkmenu.item(0).getAttribute("href"); //添加链接
            if (the_url.indexOf(linkmenu.item(0).getAttribute("href").toLowerCase()) != -1) {//选中菜单
                menuary.item(i).className = "selmenu";
            }
            else {
                menuary.item(i).onmouseover = function () { this.className = "selmenu"; }
                menuary.item(i).onmouseout = function () { this.className=""; }
            }
        }
    }
}

function selthemenu1(obj, the_url) {
    var menuary = obj.getElementsByTagName("a");
    for (var i = 0; i < menuary.length; i++) {
        if (the_url.toLowerCase().indexOf(menuary.item(i).getAttribute("href").toLowerCase()) != -1) {//选中菜单
            menuary.item(i).parentNode.className = "selmenu";
        }
        else {
            menuary.item(i).parentNode.onmouseover = function () { this.className = "selmenu"; }
            menuary.item(i).parentNode.onmouseout = function () { this.className = ""; }
        }
    }
}

function selthemenu2(obj, the_url) {
    var menuary = obj.getElementsByTagName("a");
    for (var i = 0; i < menuary.length; i++) {
        //if (the_url.toLowerCase().indexOf(menuary.item(i).getAttribute("href").toLowerCase()) != -1) {//选中菜单
        if (menuary.item(i).getAttribute("href").toLowerCase().indexOf(the_url.toLowerCase()) != -1&&the_url.length>0) {//选中菜单
            menuary.item(i).className = "selmenu";
        }
        else {
            //menuary.item(i).setAttribute("onmouseover", "this.className='selmenu'");
            menuary.item(i).onmouseover = function () { this.className = "selmenu"; }
            menuary.item(i).onmouseout = function () { this.className = "";}
        }
    }
}

//回车提交
//e:事件参数-event：直接填event就是了
//obj：事件对象,this
//str：点击的对象的ID
function strdown1(e, obj, str) {
    if (document.documentElement) {
        e = e ? e : window.event;
        var keyCode = e.which ? e.which : e.keyCode;
        if (keyCode == 13) {
            document.getElementById(str).focus();
            //event.keyCode=0;
            if (e.which) {
                e.which = 0;
            } else {
                e.keyCode = 0;
            }
        }
    }
}
//通用事件注册函数
//elm:注册事件的对象
//evType:注册的事件,不带on
//fn:注册的函数
//useCapture:执行顺序
function addEvent(elm, evType, fn, useCapture) {
    if (elm.addEventListener) {
        elm.addEventListener(evType, fn, useCapture); //DOM2.0
        return true;
    }
    else if (elm.attachEvent) {
        var r = elm.attachEvent('on' + evType, fn); //IE5+
        return r;
    }
    else {
        elm['on' + evType] = fn; //DOM 0
    }
}


//----------------------------------------------------不可重用方法---------------------------------------------------------

var timeKefu = null;
function showhidekefu(thekefu) {
    
    if (timeKefu != null) return;
    //if (thekefu.offsetLeft + 70 >= document.documentElement.offsetWidth) {
    if(is_showkf){
    } else {
        timeKefu = setInterval(function () { hide(thekefu) }, 30);
    }
}

function hide(thekefu) {
    if (thekefu.offsetLeft + 70 < document.documentElement.offsetWidth) {
        thekefu.style.left = thekefu.offsetLeft + 30 + "px";
    } else {
        thekefu.style.left = document.documentElement.offsetWidth - 70 + "px";
        clearInterval(timeKefu);
        timeKefu = null;
        is_showkf = true;
    }
}
function show(thekefu) {
    
    if (thekefu.offsetLeft + thekefu.offsetWidth > document.documentElement.offsetWidth) {
        thekefu.style.left = thekefu.offsetLeft - 30 + "px";
    } else {
        thekefu.style.left = document.documentElement.offsetWidth - thekefu.offsetWidth + "px";
        clearInterval(timeKefu);
        timeKefu = null;
    }
}

var is_showkf = true;
function showkf(thekefu) {
    //alert(thekefu.offsetLeft + 70 + "|" + document.documentElement.offsetWidth);
    if (timeKefu != null) return;
//    if (!is_showkf) return;
//    if (thekefu.offsetLeft + 100 >= document.documentElement.offsetWidth) {
    if(is_showkf){
        timeKefu = setInterval(function () { show(thekefu) }, 30);
        is_showkf = false;
    } 
}